package com.freightoa.foundation

import android.annotation.SuppressLint
import android.content.Context
import androidx.multidex.MultiDexApplication
import com.freightoa.foundation.app.ActivityLifecycleCallbacksImpl

/**
 * 作者：lhgray on 2025/3/23.
 * 邮箱：lhgray@163.com
 * 文件：
 */
open class BaseApplication : MultiDexApplication() {
    //private val mCoroutineScope by lazy(mode = LazyThreadSafetyMode.NONE) { MainScope() }

   // private val mLoadModuleProxy by lazy(mode = LazyThreadSafetyMode.NONE) { LoadModuleProxy() }

    companion object {
        // 全局Context
        @SuppressLint("StaticFieldLeak")
        lateinit var context: Context

        @SuppressLint("StaticFieldLeak")
        lateinit var application: BaseApplication
    }

    override fun attachBaseContext(base: Context) {
        super.attachBaseContext(base)
        context = base
        application = this
       // mLoadModuleProxy.onAttachBaseContext(base)
    }

    override fun onCreate() {
        super.onCreate()

        // 全局监听 Activity 生命周期
        registerActivityLifecycleCallbacks(ActivityLifecycleCallbacksImpl())
        initDepends()
    }

    private fun initDepends() {
//        // 前台初始化
//        val allTimeMillis = measureTimeMillis {
//            val depends = mLoadModuleProxy.initByFrontDesk()
//            var dependInfo: String
//            depends.forEach {
//                val dependTimeMillis = measureTimeMillis { dependInfo = it() }
//                Timber.tag("BaseApplication").d("initDepends: $dependInfo : $dependTimeMillis ms")
//            }
//        }
//        Timber.tag("BaseApplication").d("初始化完成 $allTimeMillis ms")

    }

    override fun onTerminate() {
        super.onTerminate()
        //mLoadModuleProxy.onTerminate(this)
      //  mCoroutineScope.cancel()
    }
}